import { INCREMENT, DECREMENT } from './constants'
export default function reducer(state = { count: 0, msg: '呵呵' }, action) {
  // console.log('reducer函数被调用了', state, action)
  //state 就是源数据
  // action 就是要如何修改数据的描述对象
  switch (action.type) {
    case INCREMENT:
      // ...操作数据,对数据进行递增
      // const result = state.count + 1
      return {
        ...state, //写...state的目的是为了保留不需要修改的数据
        // count: 0,
        // msg: '呵呵'
        count: state.count + action.num,
      }
    case DECREMENT:
      // const result = staet.count - 1
      return {
        ...state,
        count: state.count - action.num,
      }

    default:
      return state
  }
}
